package me.hl.javaslang;

import javaslang.concurrent.Future;
import org.junit.Test;

/**
 * Created by pulangke on 2016/12/26.
 */
public class FeatureTest {
    @Test
    public void testFeature() {
        Future<Integer> future = Future.of(() -> {
            Thread.sleep(11111);
            return 2 / 2;
        });
        future.await();
        future.onSuccess((x) -> System.out.println(x)).onFailure(throwable -> System.out.println(throwable));
    }

    @Test
    public void testFeature1() throws Exception {
        Future<Integer> future = Future.of(() -> {
            Thread.sleep(6666);
            return 2 / 2;
        });

        for (int i = 0; i < 15; i++) {
            if (future.isCompleted()) {
                System.out.println(future.get());
                break;
            } else {
                System.out.println("waiting");
            }
            Thread.sleep(1000);
        }

    }
}
